package com.laiketui.order.controller;

import com.laiketui.core.exception.LaiKeAPIException;
import com.laiketui.order.api.dto.MchOrderDTO;
import com.laiketui.order.api.dto.MchPrintTagInfoDTO;
import com.laiketui.order.api.page.MyPage;
import com.laiketui.order.api.params.mch.*;
import com.laiketui.order.service.MchOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

@RestController
@RequestMapping("/v2/mch")
public class MchOrderController {
    @Autowired
   private MchOrderService mchOrderService;

    @PostMapping("/list")
    public MyPage<MchOrderDTO> getOrderList(@RequestBody MchOrderListParams params){
        if(Objects.isNull(params.getMchId())){
            return MyPage.empty();
        }
        return mchOrderService.getOrderList(params);
    }

    @PostMapping("/confirm")
    public String confirm(@RequestBody MchOrderConfirmParams params){
        if(Objects.isNull(params.getMchId())){
            throw new LaiKeAPIException("参数错误");
        }
        return mchOrderService.confirm(params);
    }
    @PostMapping("/info")
    public MchOrderDTO info(@RequestBody MchOrderInfoParams params){
        if(Objects.isNull(params.getMchId())){
            throw new LaiKeAPIException("参数错误");
        }
        return mchOrderService.info(params);
    }
    //商品备货完成
    @PostMapping("/ready")
    public String ready(@RequestBody MchOrderDetailReadyParams params){
        if(Objects.isNull(params.getMchId())){
            throw new LaiKeAPIException("参数错误");
        }
        return mchOrderService.ready(params);
    }
    @PostMapping("/revoke")
    public String revoke(@RequestBody MchOrderDetailReadyParams params){
        if(Objects.isNull(params.getMchId())){
            throw new LaiKeAPIException("参数错误");
        }
        return mchOrderService.revoke(params);
    }

    @PostMapping("/send")
    public String send(@RequestBody MchOrderSendParams params){
        if(Objects.isNull(params.getMchId())){
            throw new LaiKeAPIException("参数错误");
        }
        if(Objects.isNull(params.getPhoto())){
            throw new LaiKeAPIException("发货单图片不能为空");
        }
        return mchOrderService.send(params);
    }

    @PostMapping("/printTagInfo")
    public MchPrintTagInfoDTO printTagInfo(@RequestBody MchOrderDetailParams params){
        if(Objects.isNull(params.getMchId())){
            throw new LaiKeAPIException("参数错误");
        }
        return mchOrderService.printTagInfo(params);
    }

    @PostMapping("/sendUpdate")
    public String sendUpdate(@RequestBody MchOrderSendParams params){
        if(Objects.isNull(params.getMchId())){
            throw new LaiKeAPIException("参数错误");
        }
        if(Objects.isNull(params.getPhoto())){
            throw new LaiKeAPIException("发货单图片不能为空");
        }
        return mchOrderService.sendUpdate(params);
    }

    @PostMapping("/shipment")
    public String shipment(@RequestBody MchOrderInfoParams params){
        if(Objects.isNull(params.getMchId())){
            throw new LaiKeAPIException("参数错误");
        }
        return mchOrderService.shipment(params);
    }

    @PostMapping("/shipmentCancel")
    public String shipmentCancel(@RequestBody MchOrderInfoParams params){
        if(Objects.isNull(params.getMchId())){
            throw new LaiKeAPIException("参数错误");
        }
        return mchOrderService.shipmentCancel(params);
    }
}
